package com.tc.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
//注解启用Swagger2接口
@EnableSwagger2
public class Swagger2Config {
    @Bean
    public Docket createRequestApi(){
        return  new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo()).select()
                //其他两种方式
                //.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                //.apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
                .apis(RequestHandlerSelectors.basePackage("com.tc.controller"))
                .build();
    }
    //http://localhost:8080/swagger-ui.html 访问查看
    /*
     * 编写ApiInfo方法
     */
    private ApiInfo apiInfo(){
        return new ApiInfoBuilder()
         .title("用户中心API")//设置标题
         .description("用户中心相关API接口")//设置描述信息
        .termsOfServiceUrl("http://localhost:9080")//设置服务器端口
        .contact(new Contact("tangcong","http://tc.org","931487909@qq.com"))//设置作者信息
        .version("1.0")//版本
        .license("唐聪个人")//版权
        .build();
    }
}
